<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ATT解锁系统接口说明</title>
    <link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link href="../static/css/style.min.css" th:href="@{/css/style.min.css}" rel="stylesheet"/>
    <style>
        .test-btn {
            margin: 10px 0;
        }
        .result-area {
            background-color: #f5f5f5;
            border: 1px solid #ddd;
            border-radius: 4px;
            padding: 15px;
            margin: 10px 0;
            min-height: 100px;
            max-height: 300px;
            overflow-y: auto;
        }
        pre {
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        .api-section {
            margin-bottom: 30px;
        }
        .api-title {
            margin-top: 20px;
            margin-bottom: 15px;
            font-weight: bold;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .success-msg {
            color: #3c763d;
            background-color: #dff0d8;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 10px;
        }
        .error-msg {
            color: #a94442;
            background-color: #f2dede;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 10px;
        }
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>API接口说明</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <h3>1. DHRU API 接口</h3>
                                <p>本系统支持DHRU API标准，可直接与DHRU客户端集成。</p>
                                
                                <h4>1.1 API基本信息</h4>
                                <p><strong>接口地址：</strong> /api/index.php</p>
                                <p><strong>请求方式：</strong> POST</p>
                                <p><strong>认证参数：</strong></p>
                                <pre>
username: admin
apiaccesskey: attunlock2024
action: 操作类型
parameters: XML格式的参数
                                </pre>
                                
                                <h4>1.2 查询账户信息</h4>
                                <p><strong>Action：</strong> accountinfo</p>
                                <p><strong>返回结果：</strong></p>
                                <pre>
{
    "SUCCESS": [
        {
            "AccountInfo": {
                "username": "admin",
                "credit": "1000",
                "currency": "USD",
                "mail": "admin@example.com"
            }
        }
    ]
}
                                </pre>
                                
                                <h4>1.3 查询余额</h4>
                                <p><strong>Action：</strong> balance</p>
                                <p><strong>返回结果：</strong></p>
                                <pre>
{
    "SUCCESS": [
        {
            "balance": 1000,
            "currency": "USD"
        }
    ]
}
                                </pre>
                                
                                <h4>1.4 获取服务列表</h4>
                                <p><strong>Action：</strong> imeiservicelist</p>
                                <p><strong>返回结果：</strong></p>
                                <pre>
{
    "SUCCESS": [
        {
            "LIST": {
                "ATT_UNLOCK": {
                    "GROUPNAME": "ATT_UNLOCK",
                    "SERVICES": {
                        "1": {
                            "SERVICEID": "1",
                            "SERVICENAME": "ATT Standard Unlock",
                            "TIME": "1-24 hours",
                            "CREDIT": "5.00",
                            "INFO": "ATT standard unlock service"
                        },
                        "2": {
                            "SERVICEID": "2",
                            "SERVICENAME": "ATT Fast Unlock",
                            "TIME": "1-6 hours",
                            "CREDIT": "8.00",
                            "INFO": "ATT fast unlock service"
                        }
                    }
                }
            }
        }
    ]
}
                                </pre>
                                
                                <h4>1.5 提交解锁订单</h4>
                                <p><strong>Action：</strong> placeimeiorder</p>
                                <p><strong>参数格式：</strong></p>
                                <pre>
&lt;PARAMETERS&gt;
&lt;IMEI&gt;123456789012345&lt;/IMEI&gt;
&lt;ID&gt;1&lt;/ID&gt;     &lt;!-- 服务ID，必须提供，对应服务列表中的SERVICEID --&gt;
&lt;/PARAMETERS&gt;
                                </pre>
                                <p><strong>返回结果：</strong></p>
                                <pre>
// 成功响应
{
    "SUCCESS": [
        {
            "REFERENCEID": "7b8f9e0a1c2d3e4f",
            "MESSAGE": "Order placed successfully"
        }
    ]
}

// 错误响应
{
    "ERROR": [
        {
            "MESSAGE": "错误信息"
        }
    ]
}
                                </pre>
                                
                                <h4>1.6 查询解锁订单状态</h4>
                                <p><strong>Action：</strong> getimeiorder</p>
                                <p><strong>参数格式：</strong></p>
                                <pre>
&lt;PARAMETERS&gt;
&lt;ID&gt;订单号&lt;/ID&gt;
&lt;/PARAMETERS&gt;
                                </pre>
                                <p><strong>返回结果：</strong></p>
                                <pre>
// 成功响应
{
    "SUCCESS": [
        {
            "STATUS": 3,          // 状态：1成功 2失败 3处理中 4等待中 5已取消
            "IMEI": "123456789012345",
            "CODE": "处理结果",
            "COMMENTS": "备注信息"
        }
    ]
}

// 错误响应
{
    "ERROR": [
        {
            "MESSAGE": "错误信息"
        }
    ]
}
                                </pre>
                                
                                <h4>1.7 调用示例</h4>
                                <pre>
// 查询账户信息
curl -X POST "http://120.77.236.187:8001/api/index.php" \
     -d "username=admin&apiaccesskey=attunlock2024&action=accountinfo&requestformat=JSON"

// 提交订单
curl -X POST "http://120.77.236.187:8001/api/index.php" \
     -d "username=admin&apiaccesskey=attunlock2024&action=placeimeiorder&parameters=&lt;PARAMETERS&gt;&lt;IMEI&gt;123456789012345&lt;/IMEI&gt;&lt;ID&gt;1&lt;/ID&gt;&lt;/PARAMETERS&gt;"

// 查询订单
curl -X POST "http://120.77.236.187:8001/api/index.php" \
     -d "username=admin&apiaccesskey=attunlock2024&action=getimeiorder&parameters=&lt;PARAMETERS&gt;&lt;ID&gt;7b8f9e0a1c2d3e4f&lt;/ID&gt;&lt;/PARAMETERS&gt;"
                                </pre>

                                <!-- 添加更新请求编号API描述 -->
                                <div class="api-section">
                                    <h3 class="api-title">2. 更新解锁请求编号接口</h3>
                                    <div class="api-desc">
                                        <p>用于在ATT确认邮件后，更新解锁记录的请求编号</p>
                                        
                                        <h4>请求信息</h4>
                                        <ul>
                                            <li><strong>URL:</strong> /unlock/request/update/{orderId}</li>
                                            <li><strong>方法:</strong> POST</li>
                                            <li><strong>路径参数:</strong>
                                                <ul>
                                                    <li>orderId - 订单号</li>
                                                </ul>
                                            </li>
                                            <li><strong>请求参数:</strong>
                                                <ul>
                                                    <li>requestNumber - ATT返回的请求编号</li>
                                                </ul>
                                            </li>
                                        </ul>
                                        
                                        <h4>返回结果</h4>
                                        <pre class="code-block json-block">
{
    "code": 200,
    "msg": "更新请求编号成功"
}
                                        </pre>
                                        
                                        <h4>错误返回</h4>
                                        <pre class="code-block json-block">
{
    "code": 500,
    "msg": "更新请求编号失败: 未找到对应的解锁记录"
}
                                        </pre>
                                        
                                        <h4>CURL示例</h4>
                                        <pre class="code-block bash-block">
curl -X POST "http://localhost:8080/unlock/request/update/abcdef1234567890" \
     -d "requestNumber=ATT123456789"
                                        </pre>

                                        <div class="test-section">
                                            <h4>测试更新请求编号</h4>
                                            <div class="form-group">
                                                <label for="test-order-id">订单号:</label>
                                                <input type="text" id="test-order-id" placeholder="输入订单号">
                                            </div>
                                            <div class="form-group">
                                                <label for="test-request-number">请求编号:</label>
                                                <input type="text" id="test-request-number" placeholder="输入ATT请求编号">
                                            </div>
                                            <button class="test-btn" onclick="testUpdateRequestNumber()">测试更新请求编号</button>
                                            <div id="update-request-result" class="result-area"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script>
        // 测试更新请求编号
        function testUpdateRequestNumber() {
            const resultArea = document.getElementById('update-request-result');
            resultArea.innerHTML = '请求中...';
            
            const orderId = document.getElementById('test-order-id').value;
            const requestNumber = document.getElementById('test-request-number').value;
            
            if (!orderId || !requestNumber) {
                resultArea.innerHTML = '<div class="error-msg">请填写订单号和请求编号</div>';
                return;
            }
            
            fetch(`/unlock/request/update/${orderId}`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: `requestNumber=${requestNumber}`
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === 200) {
                    resultArea.innerHTML = `<div class="success-msg">${data.msg}</div>
                                            <pre>${JSON.stringify(data, null, 2)}</pre>`;
                } else {
                    resultArea.innerHTML = `<div class="error-msg">${data.msg}</div>
                                            <pre>${JSON.stringify(data, null, 2)}</pre>`;
                }
            })
            .catch(error => {
                resultArea.innerHTML = `<div class="error-msg">请求失败: ${error.message}</div>`;
            });
        }
    </script>
</body>
</html>
